package cn.itcast.dao;

import cn.itcast.domain.Weibo;
import cn.itcast.domain.WeiboComm;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Date :17:36 2021/6/14
 * @Author :xuhe
 */
@Repository
public interface WeiboDao {

    @Insert("insert into weibo(id,userid,pubTime,body,image) values(#{id},#{user.userid},SYSDATE(),#{body},#{image})")
    public void publishWeibo(Weibo weibo);

    @Select("select * from weibo")
    List<Weibo> findAllWeibo();

    @Select("select * from weibo where userid=#{userid}")
    List<Weibo> findWeiboByUserid(String userid);

    @Delete("")
    void deleteWeiboByid(long weiboid);

    @Insert("insert into weiboComm(id,weiboid,commentid,beCommentid,commentDate,commentBody) values(#{id},#{weiboid},#{commentid},#{beCommentid},SYSDATE(),#{commentBody})")
    int weiboComment(WeiboComm comm);



    @Select("select userid from weibo where id=#{wId}")
    String  findUserIdbyWId(long wId);

    @Select("select * from weibo where id=#{weiboId}")
    Weibo findWeiboBywId(long weiboId);

    @Select("select comnum from weibo where id=#{weiboId}")
    int findCommNum(long weiboId);

    @Update("update weibo set comnum=#{comnum}+1 where id=#{id}")
    void updateWeibo(Weibo weibo);

    @Select("select * from weiboComm where weiboid=#{weiboid}")
    List<WeiboComm> finCommByWid(long weiboid);

    @Select("select * from weibo where body like concat('%',#{key},'%')")
    List<Weibo> search(String key);

}
